<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport">
    <title>后台主页模块 - XzcBlogTemplate后台管理</title>
    <link href="static/layui/css/layui.css" rel="stylesheet">
    <link href="static/admin/css/common.css" rel="stylesheet" type="text/css">
    <link href="static/admin/css/blogadd.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="layui-container main">
    <div class="layui-row layui-col-space20">
        <div class="layui-col-md12">
            <p>
		        	<span class="layui-breadcrumb" style="visibility: visible;">
			          	<a href="./bloglist.html">博客管理系统</a><span lay-separator="">/</span>
			          	<a href="./bloglist.html">后台首页</a><span lay-separator="">/</span>
			          	<a><cite>文章管理</cite></a>
		        	</span>
            </p>
        </div>
        <div class="layui-col-md12">
            <table class="layui-table">
                <colgroup>
                    <col width="200">
                    <col width="400">
                    <col>
                </colgroup>
                <thead>
                <tr>
                    <th>标题</th>
                    <th>内容简介</th>
                    <th>分类</th>
                    <th>是否置顶</th>
                    <th>查看数</th>
                    <th>发布时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="showht">
                <!--				    	<tr>
                                              <td>用SSM框架制作一个博客网站（响应式模板）</td>
                                              <td>我是熊五，风格迥异的四个我，有着不同的个性，不同的人格，甚至不同的职业。行险解秘专注探险的我，朝阳蓬勃酷爱嘻哈的我，精工巧匠专注纹身的我，文墨生花文艺气息满满的我。亦是我，亦非我，我是不一样的烟火。</td>
                                              <td>闲言碎语</td>
                                              <td>JAVA基础</td>
                                              <td><input type="checkbox" name="zzz" lay-skin="switch" lay-text="开启|关闭"></td>
                                              <td>267 次查看</td>
                                              <td>2022-12-12</td>
                                              <td>
                                                <a href="blogadd.html" class="layui-btn layui-btn-normal">编辑</a>
                                                <a id="del_btn" href="javascript:;" class="layui-btn layui-btn-danger">删除</a>
                                              </td>
                                        </tr>-->
                </tbody>
            </table>
        </div>
    </div>
</div>
</body>
<script src="static/js/jquery-1.12.4.min.js"></script>
<script src="static/layui/layui.all.js"></script>
<script>
    $(function () {
        $("#del_btn").click(function () {
            layer.confirm("数据已经发生改变是否确认修改？", {
                btn: ["确定", "取消"] //按钮
            }, function (index) {
                alert('点击了确认的回调函数');
                layer.close(index);
            }, function () {
                alert('点击了取消的回调函数');
                layer.close();
            });
        });
    });


</script>

<script type="text/javascript">
    $(document).ready(function () {
        //进入页面，展示所有文章
        $.get("Blog/showAllBlogs", function (rs) {
            var result = rs.result;
            $("[id='showht']").empty();
            for (var i = 0; i < result.length; i++) {
                if (result[i].status === 1) {
                    result[i].status = "置顶"
                } else {
                    result[i].status = "未置顶"
                }
                $("<tr>\n" +
                    "\t\t\t\t      \t\t<td>" + result[i].title + "</td>\n" +
                    "\t\t\t\t      \t\t<td >" + result[i].detail + "</td>\n" +
                    "\t\t\t\t      \t\t<td>" + result[i].type + "</td>\n" +
                    "\t\t\t\t      \t\t<td>" + result[i].status + "</td>\n" +
                    "\t\t\t\t      \t\t<td>" + result[i].clicknumber + " 次查看</td>\n" +
                    "\t\t\t\t      \t\t<td>" + result[i].posttime + "</td>\n" +
                    "\t\t\t\t      \t\t<td>\n" +
                    "<a  href=\"update.html\" name='bianji' id='" + result[i].blogid + "' class=\"layui-btn layui-btn-normal\">编辑</a>\n" +
                    "<a  id=\"del_btn\" href=\"javascript:;\" name='" + result[i].blogid + "' class=\"layui-btn layui-btn-danger\">删除</a>\n" +
                    "\t\t\t\t      \t\t</td>\n" +
                    "\t\t\t\t    \t</tr>").appendTo("[id='showht']");
            }
        });
    });

    //删除文章
    $(document).on("click", "[class='layui-btn layui-btn-danger']", function () {
        var blogid = $(this).attr("name");
        $.get("Blog/delete", {"blogid": blogid}, function (rs) {
            var results = rs.result;
            //自动刷新页面，重新加载文章信息
            location.reload();
        });
    });

    //根据id进行编辑，把id传给跳转的页面
    $(document).on("click", "[name='bianji']", function () {
        var blogid = $(this).attr("id");
        sessionStorage.setItem("blogid", blogid);
        window.location.href = "http://127.0.0.1:8089/update.html";
    });
</script>
</html>